import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { viteMockServe } from 'vite-plugin-mock'
import path from 'path'

export default defineConfig({
  base: '/',
  publicDir: 'public',
  plugins: [
    // Mock插件应该放在前面，确保优先拦截API请求
    viteMockServe({
      mockPath: 'mock',
      localEnabled: true, // 强制启用mock
      logger: true,
      injectCode: `
        import { setupProdMockServer } from '@/mock';
        setupProdMockServer();
      `,
      // 明确指定要拦截的URL前缀
      include: ['**/api/**']
    }),
    vue()
  ],
  
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src')
    },
    // 只保留JavaScript相关扩展
    extensions: ['.js', '.vue', '.json']
  },
  
  server: {
    port: 5175,
    host: true,
    open: true
  },
  
  // 移除所有TypeScript相关配置
  build: {
    target: 'esnext'
  }
})